package com.example.sqlitelogin;

import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.example.sqlitelogin.tools.CustomWhiteActionBar;

public class WiFiActivity extends AppCompatActivity {
    private LinearLayout l123;
    private TextView textView,num_decive,dev1,dev2,dev3,dev4;
    private ImageView imageView1,imageView2;
    private int x,num;
    private String string;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //状态栏中的文字颜色和图标颜色，需要android系统6.0以上，而且目前只有一种可以修改（一种是深色，一种是浅色即白色）
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //修改为深色，因为我们把状态栏的背景色修改为主题色白色，默认的文字及图标颜色为白色，导致看不到了。
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        setContentView(R.layout.activity_wifi);

        CustomWhiteActionBar actionBar20 = findViewById(R.id.action_bar_20);
        actionBar20.setStyle("客厅 WIFI");

        l123=findViewById(R.id.wifi_power);
        textView=findViewById(R.id.wifi_power_text);
        imageView1=findViewById(R.id.image_power_wifi1);
        imageView2=findViewById(R.id.image_power_wifi2);
        num_decive=findViewById(R.id.num_device);
        x=1;

        l123.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(x==1){
                    textView.setText("开启");

                    num_decive.setText(num+"台");
                    imageView1.setVisibility(imageView1.VISIBLE);
                    imageView2.setVisibility(imageView2.INVISIBLE);
                    x=0;
                }else {
                    textView.setText("关闭");
                    num_decive.setText("0台");
                    imageView1.setVisibility(imageView1.INVISIBLE);
                    imageView2.setVisibility(imageView2.VISIBLE);
                    x=1;
                    dev1.setText("");
                    dev2.setText("");
                    dev3.setText("");
                    dev4.setText("");
                    num=0;
                }

            }
        });

        LinearLayout add_wiFi=findViewById(R.id.add_device);
        LinearLayout linearLayout=findViewById(R.id.add_wifi);
        dev1=findViewById(R.id.de1);
        dev2=findViewById(R.id.de2);
        dev3=findViewById(R.id.de3);
        dev4=findViewById(R.id.de4);
        add_wiFi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (x==0){
                        Log.e("leo","A");
                        AlertDialog.Builder builder = new AlertDialog.Builder(WiFiActivity.this);
                        builder.setTitle("请输入设备名称");    //设置对话框标题
                        EditText edit = new EditText(WiFiActivity.this);
                        builder.setView(edit);

                        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                                string=edit.getText().toString();
                                if(num==0){
                                    dev1.setText(string);
                                }else if (num==1){
                                    dev2.setText(string);
                                }else if (num==2){
                                    dev3.setText(string);
                                }else if (num==3){
                                    dev4.setText(string);
                                }
                                num++;
                                num_decive.setText(num+"台");

                            }
                        });
                        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        });
                        builder.show();
                    }

                }
        });




    }
}
